// 永久保留在浏览器中，除非手动删除或调用remove/clear
export function localSet(
  key: string,
  value: object | string | Array<any> | boolean
) {
  localStorage.setItem(key, JSON.stringify(value));
}

export function localGet(key: string) {
  const item = localStorage.getItem(key);
  if (item) return JSON.parse(item);
  return "";
}
export function localRemove(key: string) {
  localStorage.removeItem(key);
}
export function localClear() {
  localStorage.clear();
}

// 当前会话连接时保留，浏览器系统页关闭即被销毁或调用sessionRemove/sessionClear
export function sessionSet(key: string, value: object | string | Array<any>) {
  sessionStorage.setItem(key, JSON.stringify(value));
}
export function sessionGet(key: string) {
  const item = sessionStorage.getItem(key);
  if (item) return JSON.parse(item);
  return "";
}
export function sessionRemove(key: string) {
  sessionStorage.removeItem(key);
}
export function sessionClear() {
  sessionStorage.clear();
}
